package com.taiguan.eis.solution.eiswebservice.serviceimpl;

import com.taiguan.eis.solution.eiswebservice.service.EqpWebService;
import lombok.extern.slf4j.Slf4j;
import org.w3c.dom.Document;
import org.w3c.dom.Element;


import javax.annotation.Resource;
import javax.jws.WebService;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.ByteArrayOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

@Slf4j
@WebService(name = "EqpService",
        targetNamespace = "http://service.webservice.com.taiguan.eis",
        endpointInterface = "com.taiguan.eis.solution.eiswebservice.service.EqpWebService")
public class EqpWebServiceImpl implements EqpWebService {
    @Resource
    SenderService senderService;

    @Override
    public String TrackOutLot(String _LotName, String _MachineName, String _MaterialName) {
        log.info("recv--------------------TrackOutLot");
        String xmlString = "";
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            try {
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document document = builder.newDocument();
                document.setXmlStandalone(true);
                Element message = document.createElement("Message");
                document.appendChild(message);

                Element header = document.createElement("Header");
                message.appendChild(header);

                Element body = document.createElement("Body");
                message.appendChild(body);

                Element messageName = document.createElement("MESSAGENAME");
                messageName.setTextContent("TrackOutLot");
                header.appendChild(messageName);

                Element shopName = document.createElement("SHOPNAME");
                shopName.setTextContent("208");
                header.appendChild(shopName);

                Element machinename = document.createElement("MACHINENAME");
                header.appendChild(machinename);

                Date ss = new Date();
                SimpleDateFormat format0 = new SimpleDateFormat("yyyyMMddHHmmssSSSSSS");
                String time = format0.format(ss.getTime());
                Element transactionid = document.createElement("TRANSACTIONID");
                transactionid.setTextContent(time);
                header.appendChild(transactionid);

                Element originalsourcesubjectname = document.createElement("ORIGINALSOURCESUBJECTNAME");
                header.appendChild(originalsourcesubjectname);

                Element sourcesubjectname = document.createElement("SOURCESUBJECTNAME");
                header.appendChild(sourcesubjectname);

                Element targetsubjectname = document.createElement("TARGETSUBJECTNAME");
                header.appendChild(targetsubjectname);


                Element eventuser = document.createElement("EVENTUSER");
                eventuser.setTextContent(_MachineName);
                header.appendChild(eventuser);

                Element eventcomment = document.createElement("EVENTCOMMENT");
                eventcomment.setTextContent("TrackOutLot");
                header.appendChild(eventcomment);

                Element inputset = document.createElement("INPUTSET");
                header.appendChild(inputset);

                Element language = document.createElement("LANGUAGE");
                language.setTextContent("Chinese");
                header.appendChild(language);

                /*Body Section*/

                Element lotName = document.createElement("LOTNAME");
                lotName.setTextContent(_LotName);
                body.appendChild(lotName);

                Element machineName = document.createElement("MACHINENAME");
                machineName.setTextContent(_MachineName);
                body.appendChild(machineName);

                Element materialeName = document.createElement("MATERIALNAME");
                materialeName.setTextContent(_MaterialName);
                body.appendChild(materialeName);

                TransformerFactory transFactory = TransformerFactory.newInstance();
                Transformer transformer = transFactory.newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                DOMSource domSource = new DOMSource(document);

                // xml transform String
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                transformer.transform(domSource, new StreamResult(bos));
                xmlString = bos.toString();

            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) {
            transformerFactoryConfigurationError.printStackTrace();
        }
        return senderService.SendRequest(xmlString);
    }

    @Override
    public String MaterialKitting(String _MachineName, String _MachineGroupName, String _ConsumableType, String _ConsumableSpecName, String _ConsumableName, String _Quantity) {
        log.info("recv--------------------MaterialKitting");
        String xmlString = "";
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            try {
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document document = builder.newDocument();
                document.setXmlStandalone(true);
                Element message = document.createElement("Message");
                document.appendChild(message);

                Element header = document.createElement("Header");
                message.appendChild(header);

                Element body = document.createElement("Body");
                message.appendChild(body);

                Element messageName = document.createElement("MESSAGENAME");
                messageName.setTextContent("MaterialKitting");
                header.appendChild(messageName);

                Element shopName = document.createElement("SHOPNAME");
                shopName.setTextContent("208");
                header.appendChild(shopName);

                Element machinename = document.createElement("MACHINENAME");
                machinename.setTextContent(_MachineName);
                header.appendChild(machinename);

                Date ss = new Date();
                SimpleDateFormat format0 = new SimpleDateFormat("yyyyMMddHHmmssSSSSSS");
                String time = format0.format(ss.getTime());
                Element transactionid = document.createElement("TRANSACTIONID");
                transactionid.setTextContent(time);
                header.appendChild(transactionid);

                Element originalsourcesubjectname = document.createElement("ORIGINALSOURCESUBJECTNAME");
                header.appendChild(originalsourcesubjectname);

                Element sourcesubjectname = document.createElement("SOURCESUBJECTNAME");
                header.appendChild(sourcesubjectname);

                Element targetsubjectname = document.createElement("TARGETSUBJECTNAME");
                header.appendChild(targetsubjectname);


                Element eventuser = document.createElement("EVENTUSER");
                eventuser.setTextContent(_MachineName);
                header.appendChild(eventuser);

                Element eventcomment = document.createElement("EVENTCOMMENT");
                eventcomment.setTextContent("MaterialKitting");
                header.appendChild(eventcomment);

                Element inputset = document.createElement("INPUTSET");
                header.appendChild(inputset);

                Element language = document.createElement("LANGUAGE");
                language.setTextContent("Chinese");
                header.appendChild(language);

                /*Body Section*/
                Element machineName = document.createElement("MACHINENAME");
                machineName.setTextContent(_MachineName);
                body.appendChild(machineName);

                Element machingGroupName = document.createElement("MACHINEGROUPNAME");
                machingGroupName.setTextContent(_MachineGroupName);
                body.appendChild(machingGroupName);

                Element ConsumableType = document.createElement("CONSUMABLETYPE");
                ConsumableType.setTextContent(_ConsumableType);
                body.appendChild(ConsumableType);

                Element ConsumableSpecName = document.createElement("CONSUMABLESPECNAME");
                ConsumableSpecName.setTextContent(_ConsumableSpecName);
                body.appendChild(ConsumableSpecName);

                Element ConsumableName = document.createElement("CONSUMABLENAME");
                ConsumableName.setTextContent(_ConsumableName);
                body.appendChild(ConsumableName);

                Element Quantity = document.createElement("QUANTITY");
                Quantity.setTextContent(_Quantity);
                body.appendChild(Quantity);

                TransformerFactory transFactory = TransformerFactory.newInstance();
                Transformer transformer = transFactory.newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                DOMSource domSource = new DOMSource(document);

                // xml transform String
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                transformer.transform(domSource, new StreamResult(bos));
                xmlString = bos.toString();
                System.out.println(xmlString);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) {
            transformerFactoryConfigurationError.printStackTrace();
        }
        return senderService.SendRequest(xmlString);
    }


    @Override
    public String MaterialDeKitting(String _MachineName, String _MachineGroupName, String _ConsumableType, String _ConsumableSpecName, String _ConsumableName, String _Quantity) {
        log.info("recv--------------------MaterialDeKitting");
        String xmlString = "";
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            try {
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document document = builder.newDocument();
                document.setXmlStandalone(true);
                Element message = document.createElement("Message");
                document.appendChild(message);

                Element header = document.createElement("Header");
                message.appendChild(header);

                Element body = document.createElement("Body");
                message.appendChild(body);

                Element messageName = document.createElement("MESSAGENAME");
                messageName.setTextContent("MaterialDeKitting");
                header.appendChild(messageName);

                Element shopName = document.createElement("SHOPNAME");
                shopName.setTextContent("208");
                header.appendChild(shopName);

                Element machinename = document.createElement("MACHINENAME");
                machinename.setTextContent(_MachineName);
                header.appendChild(machinename);

                Date ss = new Date();
                SimpleDateFormat format0 = new SimpleDateFormat("yyyyMMddHHmmssSSSSSS");
                String time = format0.format(ss.getTime());
                Element transactionid = document.createElement("TRANSACTIONID");
                transactionid.setTextContent(time);
                header.appendChild(transactionid);

                Element originalsourcesubjectname = document.createElement("ORIGINALSOURCESUBJECTNAME");
                header.appendChild(originalsourcesubjectname);

                Element sourcesubjectname = document.createElement("SOURCESUBJECTNAME");
                header.appendChild(sourcesubjectname);

                Element targetsubjectname = document.createElement("TARGETSUBJECTNAME");
                header.appendChild(targetsubjectname);


                Element eventuser = document.createElement("EVENTUSER");
                eventuser.setTextContent(_MachineName);
                header.appendChild(eventuser);

                Element eventcomment = document.createElement("EVENTCOMMENT");
                eventcomment.setTextContent("MaterialDeKitting");
                header.appendChild(eventcomment);

                Element inputset = document.createElement("INPUTSET");
                header.appendChild(inputset);

                Element language = document.createElement("LANGUAGE");
                language.setTextContent("Chinese");
                header.appendChild(language);

                /*Body Section*/
                Element machineName = document.createElement("MACHINENAME");
                machineName.setTextContent(_MachineName);
                body.appendChild(machineName);

                Element machingGroupName = document.createElement("MACHINEGROUPNAME");
                machingGroupName.setTextContent(_MachineGroupName);
                body.appendChild(machingGroupName);

                Element ConsumableType = document.createElement("CONSUMABLETYPE");
                ConsumableType.setTextContent(_ConsumableType);
                body.appendChild(ConsumableType);

                Element ConsumableSpecName = document.createElement("CONSUMABLESPECNAME");
                ConsumableSpecName.setTextContent(_ConsumableSpecName);
                body.appendChild(ConsumableSpecName);

                Element ConsumableName = document.createElement("CONSUMABLENAME");
                ConsumableName.setTextContent(_ConsumableName);
                body.appendChild(ConsumableName);

                Element Quantity = document.createElement("QUANTITY");
                Quantity.setTextContent(_Quantity);
                body.appendChild(Quantity);

                TransformerFactory transFactory = TransformerFactory.newInstance();
                Transformer transformer = transFactory.newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                DOMSource domSource = new DOMSource(document);

                // xml transform String
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                transformer.transform(domSource, new StreamResult(bos));
                xmlString = bos.toString();
                System.out.println(xmlString);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) {
            transformerFactoryConfigurationError.printStackTrace();
        }
        return senderService.SendRequest(xmlString);
    }

    @Override
    public String UnitStateChanged(String _MachineName, String _UnitName, String _UnitStateName) {
        log.info("recv--------------------UnitStateChanged");
        String xmlString = "";
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            try {
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document document = builder.newDocument();
                document.setXmlStandalone(true);
                Element message = document.createElement("Message");
                document.appendChild(message);

                Element header = document.createElement("Header");
                message.appendChild(header);

                Element body = document.createElement("Body");
                message.appendChild(body);

                Element messageName = document.createElement("MESSAGENAME");
                messageName.setTextContent("UnitStateChanged");
                header.appendChild(messageName);

                Element shopName = document.createElement("SHOPNAME");
                shopName.setTextContent("208");
                header.appendChild(shopName);

                Element machinename = document.createElement("MACHINENAME");
                machinename.setTextContent(_MachineName);
                header.appendChild(machinename);

                Date ss = new Date();
                SimpleDateFormat format0 = new SimpleDateFormat("yyyyMMddHHmmssSSSSSS");
                String time = format0.format(ss.getTime());
                Element transactionid = document.createElement("TRANSACTIONID");
                transactionid.setTextContent(time);
                header.appendChild(transactionid);

                Element originalsourcesubjectname = document.createElement("ORIGINALSOURCESUBJECTNAME");
                header.appendChild(originalsourcesubjectname);

                Element sourcesubjectname = document.createElement("SOURCESUBJECTNAME");
                header.appendChild(sourcesubjectname);

                Element targetsubjectname = document.createElement("TARGETSUBJECTNAME");
                header.appendChild(targetsubjectname);


                Element eventuser = document.createElement("EVENTUSER");
                eventuser.setTextContent(_MachineName);
                header.appendChild(eventuser);

                Element eventcomment = document.createElement("EVENTCOMMENT");
                eventcomment.setTextContent("UnitStateChanged");
                header.appendChild(eventcomment);

                Element inputset = document.createElement("INPUTSET");
                header.appendChild(inputset);

                Element language = document.createElement("LANGUAGE");
                language.setTextContent("Chinese");
                header.appendChild(language);

                /*Body Section*/
                Element machineName = document.createElement("MACHINENAME");
                machineName.setTextContent(_MachineName);
                body.appendChild(machineName);

                Element unitName = document.createElement("UNITNAME");
                unitName.setTextContent(_UnitName);
                body.appendChild(unitName);

                Element unitStateName = document.createElement("UNITSTATENAME");
                unitStateName.setTextContent(_UnitStateName);
                body.appendChild(unitStateName);

                TransformerFactory transFactory = TransformerFactory.newInstance();
                Transformer transformer = transFactory.newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                DOMSource domSource = new DOMSource(document);

                // xml transform String
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                transformer.transform(domSource, new StreamResult(bos));
                xmlString = bos.toString();
                System.out.println(xmlString);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) {
            transformerFactoryConfigurationError.printStackTrace();
        }
        return senderService.SendRequest(xmlString);
    }

    @Override
    public String MachineStateChanged(String _MachineName, String _MachineStateName) {
        log.info("recv--------------------MachineStateChanged");
        String xmlString = "";
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            try {
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document document = builder.newDocument();
                document.setXmlStandalone(true);
                Element message = document.createElement("Message");
                document.appendChild(message);

                Element header = document.createElement("Header");
                message.appendChild(header);

                Element body = document.createElement("Body");
                message.appendChild(body);

                Element messageName = document.createElement("MESSAGENAME");
                messageName.setTextContent("MachineStateChanged");
                header.appendChild(messageName);

                Element shopName = document.createElement("SHOPNAME");
                shopName.setTextContent("208");
                header.appendChild(shopName);

                Element machinename = document.createElement("MACHINENAME");
                machinename.setTextContent(_MachineName);
                header.appendChild(machinename);

                Date ss = new Date();
                SimpleDateFormat format0 = new SimpleDateFormat("yyyyMMddHHmmssSSSSSS");
                String time = format0.format(ss.getTime());
                Element transactionid = document.createElement("TRANSACTIONID");
                transactionid.setTextContent(time);
                header.appendChild(transactionid);

                Element originalsourcesubjectname = document.createElement("ORIGINALSOURCESUBJECTNAME");
                header.appendChild(originalsourcesubjectname);

                Element sourcesubjectname = document.createElement("SOURCESUBJECTNAME");
                header.appendChild(sourcesubjectname);

                Element targetsubjectname = document.createElement("TARGETSUBJECTNAME");
                header.appendChild(targetsubjectname);


                Element eventuser = document.createElement("EVENTUSER");
                eventuser.setTextContent(_MachineName);
                header.appendChild(eventuser);

                Element eventcomment = document.createElement("EVENTCOMMENT");
                eventcomment.setTextContent("MachineStateChanged");
                header.appendChild(eventcomment);

                Element inputset = document.createElement("INPUTSET");
                header.appendChild(inputset);

                Element language = document.createElement("LANGUAGE");
                language.setTextContent("Chinese");
                header.appendChild(language);

                /*Body Section*/
                Element machineName = document.createElement("MACHINENAME");
                machineName.setTextContent(_MachineName);
                body.appendChild(machineName);

                Element machineStateName = document.createElement("MACHINESTATENAME");
                machineStateName.setTextContent(_MachineStateName);
                body.appendChild(machineStateName);

                TransformerFactory transFactory = TransformerFactory.newInstance();
                Transformer transformer = transFactory.newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                DOMSource domSource = new DOMSource(document);

                // xml transform String
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                transformer.transform(domSource, new StreamResult(bos));
                xmlString = bos.toString();
                System.out.println(xmlString);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) {
            transformerFactoryConfigurationError.printStackTrace();
        }
        return senderService.SendRequest(xmlString);
    }

    @Override
    public String AlarmReport(String _MachineName, String _UnitName, String _AlarmID, String _AlarmState, String _AlarmSeverity, String _AlarmText) {
        log.info("recv--------------------AlarmReport");
        String xmlString = "";
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            try {
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document document = builder.newDocument();
                document.setXmlStandalone(true);
                Element message = document.createElement("Message");
                document.appendChild(message);

                Element header = document.createElement("Header");
                message.appendChild(header);

                Element body = document.createElement("Body");
                message.appendChild(body);

                Element messageName = document.createElement("MESSAGENAME");
                messageName.setTextContent("AlarmReport");
                header.appendChild(messageName);

                Element shopName = document.createElement("SHOPNAME");
                shopName.setTextContent("208");
                header.appendChild(shopName);

                Element machinename = document.createElement("MACHINENAME");
                machinename.setTextContent(_MachineName);
                header.appendChild(machinename);

                Date ss = new Date();
                SimpleDateFormat format0 = new SimpleDateFormat("yyyyMMddHHmmssSSSSSS");
                String time = format0.format(ss.getTime());
                Element transactionid = document.createElement("TRANSACTIONID");
                transactionid.setTextContent(time);
                header.appendChild(transactionid);

                Element originalsourcesubjectname = document.createElement("ORIGINALSOURCESUBJECTNAME");
                header.appendChild(originalsourcesubjectname);

                Element sourcesubjectname = document.createElement("SOURCESUBJECTNAME");
                header.appendChild(sourcesubjectname);

                Element targetsubjectname = document.createElement("TARGETSUBJECTNAME");
                header.appendChild(targetsubjectname);


                Element eventuser = document.createElement("EVENTUSER");
                eventuser.setTextContent(_MachineName);
                header.appendChild(eventuser);

                Element eventcomment = document.createElement("EVENTCOMMENT");
                eventcomment.setTextContent("AlarmReport");
                header.appendChild(eventcomment);

                Element inputset = document.createElement("INPUTSET");
                header.appendChild(inputset);

                Element language = document.createElement("LANGUAGE");
                language.setTextContent("Chinese");
                header.appendChild(language);

                /*Body Section*/
                Element machineName = document.createElement("MACHINENAME");
                machineName.setTextContent(_MachineName);
                body.appendChild(machineName);

                Element unitName = document.createElement("UNITNAME");
                unitName.setTextContent(_UnitName);
                body.appendChild(unitName);

                Element alarmID = document.createElement("ALARMID");
                alarmID.setTextContent(_AlarmID);
                body.appendChild(alarmID);

                Element alarmState = document.createElement("ALARMSTATE");
                alarmState.setTextContent(_AlarmState);
                body.appendChild(alarmState);

                Element alarmseverity = document.createElement("ALARMSEVERITY");
                alarmseverity.setTextContent(_AlarmSeverity);
                body.appendChild(alarmseverity);

                Element alarmtext = document.createElement("ALARMTEXT");
                alarmtext.setTextContent(_AlarmText);
                body.appendChild(alarmtext);

                Element productlist = document.createElement("PRODUCTLIST");
                body.appendChild(productlist);

                TransformerFactory transFactory = TransformerFactory.newInstance();
                Transformer transformer = transFactory.newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                DOMSource domSource = new DOMSource(document);

                // xml transform String
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                transformer.transform(domSource, new StreamResult(bos));
                xmlString = bos.toString();
                System.out.println(xmlString);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) {
            transformerFactoryConfigurationError.printStackTrace();
        }
        return senderService.SendRequest(xmlString);
    }

    @Override
    public String ProductProcessData(String _MachineName,String _UnitName, String _LotName, String _Parameters) {
        log.info("recv--------------------ProductProcessData");
        String xmlString = "";
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            try {
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document document = builder.newDocument();
                document.setXmlStandalone(true);
                Element message = document.createElement("Message");
                document.appendChild(message);

                Element header = document.createElement("Header");
                message.appendChild(header);

                Element body = document.createElement("Body");
                message.appendChild(body);

                Element messageName = document.createElement("MESSAGENAME");
                messageName.setTextContent("ProductProcessData");
                header.appendChild(messageName);

                Element shopName = document.createElement("SHOPNAME");
                shopName.setTextContent("208");
                header.appendChild(shopName);

                Element machinename = document.createElement("MACHINENAME");
                machinename.setTextContent(_MachineName);
                header.appendChild(machinename);

                Date ss = new Date();
                SimpleDateFormat format0 = new SimpleDateFormat("yyyyMMddHHmmssSSSSSS");
                String time = format0.format(ss.getTime());
                Element transactionid = document.createElement("TRANSACTIONID");
                transactionid.setTextContent(time);
                header.appendChild(transactionid);

                Element originalsourcesubjectname = document.createElement("ORIGINALSOURCESUBJECTNAME");
                header.appendChild(originalsourcesubjectname);

                Element sourcesubjectname = document.createElement("SOURCESUBJECTNAME");
                header.appendChild(sourcesubjectname);

                Element targetsubjectname = document.createElement("TARGETSUBJECTNAME");
                header.appendChild(targetsubjectname);


                Element eventuser = document.createElement("EVENTUSER");
                eventuser.setTextContent(_MachineName);
                header.appendChild(eventuser);

                Element eventcomment = document.createElement("EVENTCOMMENT");
                eventcomment.setTextContent("ProductProcessData");
                header.appendChild(eventcomment);

                Element inputset = document.createElement("INPUTSET");
                header.appendChild(inputset);

                Element language = document.createElement("LANGUAGE");
                language.setTextContent("Chinese");
                header.appendChild(language);

                /*Body Section*/
                Element machineName = document.createElement("MACHINENAME");
                machineName.setTextContent(_MachineName);
                body.appendChild(machineName);

                Element unitName = document.createElement("UNITNAME");
                unitName.setTextContent(_UnitName);
                body.appendChild(unitName);

                Element lotName = document.createElement("LOTNAME");
                lotName.setTextContent(_LotName);
                body.appendChild(lotName);

                Element iTemList = document.createElement("ITEMLIST");
                String[] itemListStr = _Parameters.split("\\|");
                if(itemListStr.length>0){
                    for(int i=0;i<itemListStr.length;i++){
                        Element iTem = document.createElement("ITEM");
                        Element iTemName = document.createElement("ITEMNAME");
                        Element siteList = document.createElement("SITELIST");
                        Element siteName = document.createElement("SITENAME");
                        Element siteValue = document.createElement("SITEVALUE");
                        String[] siteListStr = itemListStr[i].split("=");
                        if(siteListStr.length>0){
                            iTemName.setTextContent(siteListStr[0]);
                            siteName.setTextContent("G");
                            siteList.appendChild(siteName);
                            siteValue.setTextContent(siteListStr[1]);
                            siteList.appendChild(siteValue);
                            iTem.appendChild(iTemName);
                            iTem.appendChild(siteList);
                        }
                        iTemList.appendChild(iTem);
                    }
                }
                body.appendChild(iTemList);



                TransformerFactory transFactory = TransformerFactory.newInstance();
                Transformer transformer = transFactory.newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                DOMSource domSource = new DOMSource(document);

                // xml transform String
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                transformer.transform(domSource, new StreamResult(bos));
                xmlString = bos.toString();
                System.out.println(xmlString);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) {
            transformerFactoryConfigurationError.printStackTrace();
        }
        return senderService.SendRequest(xmlString);
    }

    @Override
    public String AOIJudge(String _MachineName, String _LotName,String _MaterialName, String _LotGrade, String _ReasonCode) {
        log.info("recv--------------------AOIJudge");
        String xmlString = "";
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            try {
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document document = builder.newDocument();
                document.setXmlStandalone(true);
                Element message = document.createElement("Message");
                document.appendChild(message);

                Element header = document.createElement("Header");
                message.appendChild(header);

                Element body = document.createElement("Body");
                message.appendChild(body);

                Element messageName = document.createElement("MESSAGENAME");
                messageName.setTextContent("AOIJudge");
                header.appendChild(messageName);

                Element shopName = document.createElement("SHOPNAME");
                shopName.setTextContent("208");
                header.appendChild(shopName);

                Element machinename = document.createElement("MACHINENAME");
                machinename.setTextContent(_MachineName);
                header.appendChild(machinename);

                Date ss = new Date();
                SimpleDateFormat format0 = new SimpleDateFormat("yyyyMMddHHmmssSSSSSS");
                String time = format0.format(ss.getTime());
                Element transactionid = document.createElement("TRANSACTIONID");
                transactionid.setTextContent(time);
                header.appendChild(transactionid);

                Element originalsourcesubjectname = document.createElement("ORIGINALSOURCESUBJECTNAME");
                header.appendChild(originalsourcesubjectname);

                Element sourcesubjectname = document.createElement("SOURCESUBJECTNAME");
                header.appendChild(sourcesubjectname);

                Element targetsubjectname = document.createElement("TARGETSUBJECTNAME");
                header.appendChild(targetsubjectname);


                Element eventuser = document.createElement("EVENTUSER");
                eventuser.setTextContent(_MachineName);
                header.appendChild(eventuser);

                Element eventcomment = document.createElement("EVENTCOMMENT");
                eventcomment.setTextContent("AOIJudge");
                header.appendChild(eventcomment);

                Element inputset = document.createElement("INPUTSET");
                header.appendChild(inputset);

                Element language = document.createElement("LANGUAGE");
                language.setTextContent("Chinese");
                header.appendChild(language);

                /*Body Section*/
                Element machineName = document.createElement("MACHINENAME");
                machineName.setTextContent(_MachineName);
                body.appendChild(machineName);

                Element materialName = document.createElement("MATERIALNAME");
                materialName.setTextContent(_MaterialName);
                body.appendChild(materialName);

                Element lotName = document.createElement("LOTNAME");
                lotName.setTextContent(_LotName);
                body.appendChild(lotName);

                Element lotGrade = document.createElement("LOTGRADE");
                lotGrade.setTextContent(_LotGrade);
                body.appendChild(lotGrade);

                Element reasonCode = document.createElement("REASONCODE");
                reasonCode.setTextContent(_ReasonCode);
                body.appendChild(reasonCode);

                TransformerFactory transFactory = TransformerFactory.newInstance();
                Transformer transformer = transFactory.newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                DOMSource domSource = new DOMSource(document);

                // xml transform String
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                transformer.transform(domSource, new StreamResult(bos));
                xmlString = bos.toString();
                System.out.println(xmlString);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) {
            transformerFactoryConfigurationError.printStackTrace();
        }
        return senderService.SendRequest(xmlString);
    }

    @Override
    public String AOIReJudge(String _MachineName, String _LotName,String _MaterialName , String _LotGrade, String _ReasonCode) {
        log.info("recv--------------------AOIReJudge");
        String xmlString = "";
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            try {
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document document = builder.newDocument();
                document.setXmlStandalone(true);
                Element message = document.createElement("Message");
                document.appendChild(message);

                Element header = document.createElement("Header");
                message.appendChild(header);

                Element body = document.createElement("Body");
                message.appendChild(body);

                Element messageName = document.createElement("MESSAGENAME");
                messageName.setTextContent("AOIReJudge");
                header.appendChild(messageName);

                Element shopName = document.createElement("SHOPNAME");
                shopName.setTextContent("208");
                header.appendChild(shopName);

                Element machinename = document.createElement("MACHINENAME");
                machinename.setTextContent(_MachineName);
                header.appendChild(machinename);

                Date ss = new Date();
                SimpleDateFormat format0 = new SimpleDateFormat("yyyyMMddHHmmssSSSSSS");
                String time = format0.format(ss.getTime());
                Element transactionid = document.createElement("TRANSACTIONID");
                transactionid.setTextContent(time);
                header.appendChild(transactionid);

                Element originalsourcesubjectname = document.createElement("ORIGINALSOURCESUBJECTNAME");
                header.appendChild(originalsourcesubjectname);

                Element sourcesubjectname = document.createElement("SOURCESUBJECTNAME");
                header.appendChild(sourcesubjectname);

                Element targetsubjectname = document.createElement("TARGETSUBJECTNAME");
                header.appendChild(targetsubjectname);


                Element eventuser = document.createElement("EVENTUSER");
                eventuser.setTextContent(_MachineName);
                header.appendChild(eventuser);

                Element eventcomment = document.createElement("EVENTCOMMENT");
                eventcomment.setTextContent("AOIReJudge");
                header.appendChild(eventcomment);

                Element inputset = document.createElement("INPUTSET");
                header.appendChild(inputset);

                Element language = document.createElement("LANGUAGE");
                language.setTextContent("Chinese");
                header.appendChild(language);

                /*Body Section*/
                Element machineName = document.createElement("MACHINENAME");
                machineName.setTextContent(_MachineName);
                body.appendChild(machineName);

                Element materialName = document.createElement("MATERIALNAME");
                materialName.setTextContent(_MaterialName);
                body.appendChild(materialName);

                Element lotName = document.createElement("LOTNAME");
                lotName.setTextContent(_LotName);
                body.appendChild(lotName);

                Element lotGrade = document.createElement("LOTGRADE");
                lotGrade.setTextContent(_LotGrade);
                body.appendChild(lotGrade);

                Element reasonCode = document.createElement("REASONCODE");
                reasonCode.setTextContent(_ReasonCode);
                body.appendChild(reasonCode);

                TransformerFactory transFactory = TransformerFactory.newInstance();
                Transformer transformer = transFactory.newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                DOMSource domSource = new DOMSource(document);

                // xml transform String
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                transformer.transform(domSource, new StreamResult(bos));
                xmlString = bos.toString();
                System.out.println(xmlString);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) {
            transformerFactoryConfigurationError.printStackTrace();
        }
        return senderService.SendRequest(xmlString);
    }

    @Override
    public String EMDataReport(String _MachineName, String _UnitName, String _LotName, String _Parameters) {
        log.info("recv--------------------EMDataReport");
        String xmlString = "";
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            try {
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document document = builder.newDocument();
                document.setXmlStandalone(true);
                Element message = document.createElement("Message");
                document.appendChild(message);

                Element header = document.createElement("Header");
                message.appendChild(header);

                Element body = document.createElement("Body");
                message.appendChild(body);

                Element messageName = document.createElement("MESSAGENAME");
                messageName.setTextContent("EMDataReport");
                header.appendChild(messageName);

                Element shopName = document.createElement("SHOPNAME");
                shopName.setTextContent("208");
                header.appendChild(shopName);

                Element machinename = document.createElement("MACHINENAME");
                machinename.setTextContent(_MachineName);
                header.appendChild(machinename);

                Date ss = new Date();
                SimpleDateFormat format0 = new SimpleDateFormat("yyyyMMddHHmmssSSSSSS");
                String time = format0.format(ss.getTime());
                Element transactionid = document.createElement("TRANSACTIONID");
                transactionid.setTextContent(time);
                header.appendChild(transactionid);

                Element originalsourcesubjectname = document.createElement("ORIGINALSOURCESUBJECTNAME");
                header.appendChild(originalsourcesubjectname);

                Element sourcesubjectname = document.createElement("SOURCESUBJECTNAME");
                header.appendChild(sourcesubjectname);

                Element targetsubjectname = document.createElement("TARGETSUBJECTNAME");
                header.appendChild(targetsubjectname);


                Element eventuser = document.createElement("EVENTUSER");
                eventuser.setTextContent(_MachineName);
                header.appendChild(eventuser);

                Element eventcomment = document.createElement("EVENTCOMMENT");
                eventcomment.setTextContent("EMDataReport");
                header.appendChild(eventcomment);

                Element inputset = document.createElement("INPUTSET");
                header.appendChild(inputset);

                Element language = document.createElement("LANGUAGE");
                language.setTextContent("Chinese");
                header.appendChild(language);

                /*Body Section*/
                Element machineName = document.createElement("MACHINENAME");
                machineName.setTextContent(_MachineName);
                body.appendChild(machineName);

                Element unitName = document.createElement("UNITNAME");
                unitName.setTextContent(_UnitName);
                body.appendChild(unitName);

                Element lotName = document.createElement("LOTNAME");
                lotName.setTextContent(_LotName);
                body.appendChild(lotName);

                Element iTemList = document.createElement("ITEMLIST");
                String[] itemListStr = _Parameters.split("\\|");
                if(itemListStr.length>0){
                    for(int i=0;i<itemListStr.length;i++){
                        Element iTem = document.createElement("ITEM");
                        Element iTemName = document.createElement("ITEMNAME");

                        Element iTemValue = document.createElement("ITEMVALUE");
                        String[] siteListStr = itemListStr[i].split("=");
                        if(siteListStr.length>0){
                            iTemName.setTextContent(siteListStr[0]);

                            iTemValue.setTextContent(siteListStr[1]);

                            iTem.appendChild(iTemName);
                            iTem.appendChild(iTemValue);
                        }
                        iTemList.appendChild(iTem);
                    }
                }
                body.appendChild(iTemList);



                TransformerFactory transFactory = TransformerFactory.newInstance();
                Transformer transformer = transFactory.newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                DOMSource domSource = new DOMSource(document);

                // xml transform String
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                transformer.transform(domSource, new StreamResult(bos));
                xmlString = bos.toString();
                System.out.println(xmlString);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) {
            transformerFactoryConfigurationError.printStackTrace();
        }
        return senderService.SendRequest(xmlString);
    }

}
